<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增软件模块</title>
	<base href="<%=basePath%>"/>
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:250px;}
	  input[type="password"]{width:250px;}
	  input[type="textarea"]{width:250px;}
	</style>
	<script type="text/javascript">
	  $(document).ready(function(){
	      $("#enname").focus();
	      $.ajaxSetup ({ cache:false,async: false });
	      $("#pId").mcDropdown("#categorymenu",{ dropShadow: false, targetColumnSize: 1, lineHeight:30, allowParentSelect:true});
	      var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
	      $("#moduleForm").submit(function(){
	          $(this).ajaxSubmit(options);
	          return false;
	      });  
	      $('#projectId').change(function(){ 
	    	  var projectId =  $('#projectId').val();
	    	  var queryString =  $('#qs').val();
	    	  location.href = "<%=basePath%>soft/module/insert.do?projectId=" + projectId + "&qs=" + queryString;
	      });
	   });
		  
		  function beforeSubmit() {
		      if(isEmpty($("#name").val())) { alert("名称不能为空！"); return false; }
		      return true;
		  }
	
		  function process(responseJson) {
		      if(responseJson.code == 0) {
		          $('#error_label').text("错误信息：" + responseJson.message);
		          $("#p_error").show();
		          return;
		       }
	          var qs = $("#qs").val();
	          location.href = "<%=basePath%>soft/module/list.do?" + qs;
	      }  

		  //返回列表页面
		  function btn_return(){
			   var qs = $("#qs").val();
			   location.href = "<%=basePath%>soft/module/list.do?" + qs;
		  }
	</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>新增模块：</legend>
      <form id="moduleForm" method="post" action="soft/module/insert.do">
        <input id="qs" name="qs" type="hidden" value="${qs}"/>
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
         <tr>
          <td><label for="projectId">项目：</label></td>
            <td>
                <select name="projectId" id="projectId" style="width:206px;">
	                <c:forEach items="${projectList}" var="p">
	                    <option value="${p.id}" <c:if test="${p.id == projectId}">selected</c:if>><c:out value="${p.name}"/></option>
		            </c:forEach>
	            </select>  	
            </td>
          </tr> 
          <tr>
            <td><label for="value">父模块：</label></td>
            <td>
               <c:if test="${!empty treeList}">
	               <input name="pId" id="pId" readonly="readonly"  style="width:206px;">
	               <ul id="categorymenu" class="mcdropdown_menu">
				        <c:forEach items="${treeList}" var="tree" varStatus="status">
				            ${tree}
				        </c:forEach>
			       </ul>
		       </c:if>  	
		       <c:if test="${empty treeList}">
	               <input type="text" disabled="disabled" value="请先添加父级模块" style="width:200px;">
		       </c:if>  	
            </td>
          </tr>
          <tr>
            <td><label for="name">名称：</label></td>
            <td>
            	<input type="text" name="name" id="name"  style="width:200px;" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="name">小于100位</label>
            </td>
          </tr> 
          <tr>
            <td><label>状态：</label></td>
            <td>
                 <select name="status" id="status" style="width:206px;">
		                <c:forEach items="${statusList}" var="s">
			                <option value="${s.value}" <c:if test="${status == s.value}">selected</c:if> >${s.name}</option>
			            </c:forEach>
		         </select>  	
            </td>
          </tr>            
          <tr>
            <td valign="top"><label for="description">描述：</label></td>
            <td valign="top"><textarea name="description" id="description" cols="40" rows="3"><c:out value="${item.remark }"/></textarea><label for="name">小于1000位</label></td>
          </tr>                   
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>
</body>
</html>